/*
 * @Author: 码农 2646995216@qq.com
 * @Date: 2025-02-23 20:34:27
 * @LastEditors: 码农 2646995216@qq.com
 * @LastEditTime: 2025-02-23 22:31:37
 * @FilePath: /signal/text.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <signal.h>
#include<iostream>
#include <sys/types.h>
#include <unistd.h>


using namespace std;

//abort()
/*int main()
{
	int count=0;
	while(true)
	{
		cout<<"conut:"<<count<<endl;
		count++;
		if(count==3)
		{
			abort();
		}
		sleep(1);
	}


	return 0;
}*/

//signal()
void hander(int signal)
{
	cout << "got a signal, number is : " << signal << endl;
	exit(1);
}

int main()
{
	signal(SIGALRM,hander);//将SIGALRM号信号的默认动作，替换为hander函数
	alarm(5);
    while(true)
	{
		cout<<"I am a process,pid:"<<getpid()<<endl;
		sleep(1);
	}


	return 0;
}